/**
 * Created by lyf on 2017/6/20.
 */

'use strict'

let node_ssh = require('node-ssh');
const serviceConfig = require('../conf/service.json');
let ssh = new node_ssh();

module.exports = function deployKibana(kibana , elasticsearch) {
    return new Promise (async function(resolve,reject){
        console.log(kibana);
        for ( let i = 0 ; i < kibana.length ; i++){
            await ssh.connect({
                host: kibana[i][1],
                username: serviceConfig.user ,
                password: serviceConfig.password
            });
            const result = await ssh.execCommand(`docker run --name some-kibana -e ELASTICSEARCH_URL=http://${elasticsearch[0][0]}:9200 -p 5601:5601 -d kibana`);
            ssh.dispose();

            console.log(`kibana:${kibana[i][1]}`);
            console.log(`${elasticsearch[0][0]}`);
            console.log("-----------------------------");
            console.log(result.stdout);
            console.log(result.stderr);
            console.log("-----------------------------");
            result.stdout ? resolve() : reject ();
        }
    })

}